package sg.edu.nus.iss.vmcs.controller;

import sg.edu.nus.iss.vmcs.ui.NoChangeAvailableDisplay;
import sg.edu.nus.iss.vmcs.ui.RefundChangeTrayDisplay;
/**
 * This is the Context
 * @author ManhPhamCuong
 *
 */
public class ChangeGiver {
	private static final double eps = 0.1;
	public ChangeGiverStrategy changeGiverStrategy;
	public static int currentStrategy = 1;
	public void ResetChange() {
		RefundChangeTrayDisplay refChngTrayDisp = new RefundChangeTrayDisplay();
		double changeGiven = 0; 
		refChngTrayDisp.SetValue(changeGiven); 
	}
	
	public ChangeGiver() {
		setStrategy(currentStrategy);
	}
	
	public void setStrategy(int currentStrategy){
		this.currentStrategy = currentStrategy;
		if (currentStrategy==0) {
			changeGiverStrategy = new LargestFirstChangeGiverStrategy();
		} else {
			changeGiverStrategy = new SmallestFirstChangeGivenStrategy();
		}
	}
	
	public void DisplayChangeStatus() {
		
	}

	/**
	 * give a change given amt, display the change
	 * @param changeGivenAmt
	 */
	public void giveChange(double changeGivenAmt) {
		MainController mainController = MainController.getInstance();
		setStrategy(currentStrategy);
		double remainingChange = changeGiverStrategy.giveChange(changeGivenAmt, mainController);
		if (remainingChange > ChangeGiverStrategy.eps) {
			NoChangeAvailableDisplay.getInstance().setState(NoChangeAvailableDisplay.NO_CHANGE_DISPLAY);
		}
	}
	
}
